<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateElDiscountCouponTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('el_discount_coupon', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('discount_id');
            $table->integer('user_id')->unsigned();
            $table->string('code')->nullable();
            /*$table->integer('usage_limit')->nullable(); //可使用数量
            $table->integer('used')->default(0);*/        //已使用数量
            $table->timestamp('used_at')->nullable();   //使用时间
            $table->timestamp('expires_at')->nullable();
            $table->timestamps();
            $table->softDeletes();
        });

        // 优惠券和用户的中间表，多对多的关系
        /*Schema::create('el_discount_coupon_user', function (Blueprint $table) {

            $table->increments('id');
            $table->integer('user_id')->unsigned();
            $table->integer('coupon_id')->unsigned();

            $table->timestamp('used_at')->nullable(); //使用时间
            $table->timestamp('created_at')->nullable();//获取时间
            $table->timestamp('expires_at')->nullable();//过期时间

            $table->foreign('user_id')->references('id')->on('el_user')
                ->onUpdate('cascade')->onDelete('cascade');
            $table->foreign('coupon_id')->references('id')->on('el_discount_coupon')
                ->onUpdate('cascade')->onDelete('cascade');

            $table->primary(['user_id', 'coupon_id']);
        });*/
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //Schema::drop('el_discount_coupon_user');
        Schema::drop('el_discount_coupon');
    }
}
